package com.cnsunrun.framworksimple.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.cnsunrun.framwork.common.net.CommonApi;
import com.cnsunrun.framwork.common.net.BaseBean;
import com.cnsunrun.framworksimple.R;
import com.cnsunrun.framworksimple.mode.TestBean;
import com.sunrun.sunrunframwork.uibase.BaseActivity;
import com.sunrun.sunrunframwork.uiutils.paging.IAdapter;
import com.sunrun.sunrunframwork.uiutils.paging.IRefresh;
import com.sunrun.sunrunframwork.uiutils.paging.PageLimitDelegate;
import com.sunrun.sunrunframwork.utils.log.Logger;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static com.cnsunrun.framwork.common.net.APIManager.getAPI;

/**
 * 网络请求示例
 * Created by WQ on 2017/4/20.
 */

public class NetSimpleActivity extends BaseActivity implements PageLimitDelegate.DataProvider {
    CommonApi mApi= getAPI(this,CommonApi.class);
    PageLimitDelegate pageLimitDelegate=new PageLimitDelegate(this);
    @Override
    protected int getLayoutId() {
        return R.layout.activity_main_simple;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

        SwipeRefreshLayout swipeRefreshLayout;
        BaseQuickAdapter quickAdapter;

        pageLimitDelegate.attach(new IRefresh() {
            @Override
            public void setEnabled(boolean enabled) {

            }

            @Override
            public void setEnableLoadMore(boolean enabled) {

            }

            @Override
            public void loadMoreComplete() {

            }

            @Override
            public void setRefreshing(boolean enabled) {

            }
        }, new IAdapter() {
            @Override
            public void addData(List data) {

            }

            @Override
            public void setNewData(List data) {

            }

            @Override
            public List getData() {
                return null;
            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //进行网络请求,数据返回在该类同名方法中
        mApi.getSomeInfo("6", "1", "24e7bdb5c2566e9fd423384876ae3ff6", "1", "12");

    }
    //获取返回数据,返回数据内容与接口中定义的返回值一致
    public void getSomeInfo(BaseBean<TestBean> result){
        Logger.D(result);
    }

    @Override
    public void loadData(int page) {
        List list=new ArrayList();
        list.addAll(Arrays.asList(new String[]{"1","2","3"}));
        pageLimitDelegate.setData(list);
    }
}
